package ycg_remote

import (
	"context"
	"fmt"
	"git.mycaigou.com/gfyx/common/http_client"
	"git.myscrm.cn/golang/stark/v4"
)

type ycgRepo struct{}

const (
	SaasSupplierMemberInfo = "/api/saas/supplier-saas/member-info"
)

func NewYcgRepository() YcgRepositoryIface {
	return &ycgRepo{}
}

func (r *ycgRepo) GetSaasSupplierMemberInfo(ctx context.Context, supplierName string) (*GetSaasSupplierMemberInfoData, error) {
	client := http_client.New()
	domain := stark.Configer.(stark.ApolloConfigerIface).GetStringValue("Domain.RootDomain", "")
	response := GetSaasSupplierMemberInfoResponse{}
	url := fmt.Sprintf("https://m.%s%s?supplier_name=%s", domain, SaasSupplierMemberInfo, supplierName)
	_, _, errs := client.Get(ctx, url, nil).EndStruct(&response)
	if len(errs) > 0 {
		return nil, errs[0]
	}

	if !response.Success {
		return nil, nil
	}

	return response.Data, nil
}
